package com.demo.common.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Description: WebMvcConfig
 * @Author: ChenXueLi
 * @Date: 2018-10-02 14:46
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Value("${swagger.show}")
    private boolean showSwagger;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if(showSwagger) {
            registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
            registry.addResourceHandler("swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
    }

}
